import { mockUsers, mockPermissions, mockRoles, mockLoginResponse, mockUserSession } from '@/mock'
import { mockRequest } from '@/mock'

/**
 * 用户信息接口
 */
export interface UserInfo {
  id: string
  username: string
  email: string
  avatar: string
  role: string
  status: 'active' | 'inactive'
  lastLoginTime: string
  createTime: string
}

/**
 * 用户权限接口
 */
export interface UserPermission {
  id: string
  name: string
  code: string
  description: string
  type: 'menu' | 'button' | 'api'
  parentId: string | null
  path?: string
  icon?: string
  order: number
}

/**
 * 用户角色接口
 */
export interface UserRole {
  id: string
  name: string
  code: string
  description: string
  permissions: string[]
}

/**
 * 登录请求参数
 */
export interface LoginParams {
  username: string
  password: string
  captcha?: string
  captchaId?: string
  remember?: boolean
}

/**
 * 登录响应数据
 */
export interface LoginResponse {
  code: number
  message: string
  data: {
    token: string
    userInfo: UserInfo
    permissions: string[]
    roles: string[]
  }
}

/**
 * 用户会话数据
 */
export interface UserSession {
  token: string
  userInfo: UserInfo
  permissions: string[]
  roles: string[]
  expires: string
}

/**
 * 用户API服务
 */
export const userApi = {
  /**
   * 用户登录
   */
  login: async (params: LoginParams): Promise<LoginResponse> => {
    return mockRequest(mockLoginResponse)
  },

  /**
   * 获取用户信息
   */
  getUserInfo: async (): Promise<UserInfo> => {
    return mockRequest(mockUserSession.userInfo)
  },

  /**
   * 获取用户权限
   */
  getUserPermissions: async (): Promise<UserPermission[]> => {
    return mockRequest(mockPermissions)
  },

  /**
   * 获取用户角色
   */
  getUserRoles: async (): Promise<UserRole[]> => {
    return mockRequest(mockRoles)
  },

  /**
   * 获取用户会话
   */
  getUserSession: async (): Promise<UserSession> => {
    return mockRequest(mockUserSession)
  },

  /**
   * 退出登录
   */
  logout: async (): Promise<void> => {
    return mockRequest(undefined)
  }
} 